package com.example.demo.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MapperAspect {

    Logger log = LoggerFactory.getLogger(MapperAspect.class);



    @Pointcut("execution(* com.example.demo.dao.*.*(..))")
    private void pointCutMethod() {
    }

    /**
     * 声明环绕通知
     *
     * @param pjp
     * @return
     * @throws Throwable
     */
    @Around("pointCutMethod()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        log.debug("===================== startUp =================================================");
        long   start = System.currentTimeMillis();
        Object obj   = pjp.proceed();
        long   end   = System.currentTimeMillis();
        log.debug("Class & Method: {}", pjp.getSignature().getDeclaringType().getName() + "#" + pjp.getSignature().getName());
        log.debug("    Time      ：{}ms", (end - start));
        log.debug("=====================complete==================================================");
        return obj;
    }
}